package org.haredot.mapper;

import org.apache.ibatis.annotations.*;
import org.haredot.dto.LeftMenu;
import org.haredot.entity.Menu;
import org.haredot.entity.Role;

import java.util.List;
import java.util.Map;

@Mapper
public interface MenuMapper {

    @Select("select id, name, icon, sorted, status, description, create_time, update_time, disable_time from tb_menu" +
            " where name = #{name} and flag = 0")
    Menu findMenuByName(@Param("name") String name);

    @Insert("insert into tb_menu(name, icon, sorted, description, status, create_time) " +
            "values(#{name}, #{icon}, #{sorted}, #{description}, #{status}, now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int save(Menu menu);

    @Select("select id, name, icon, sorted, status, description, create_time, update_time, disable_time " +
            "from tb_menu where flag = 0")
    List<Menu> findAll();

    int modifyStatus(Map<String, Object> param);

    int updateMenu(Menu menu);

    int removeMenuById(Long id);

    List<LeftMenu> findLeftAllMenus();

    List<LeftMenu> findLeftMenusByRoleIds(List<Role> roles);
}
